<!--
 * relative     : e:\Code\CaseManagement\case-management-web\src\components\selector\genderSelector.vue
 * Author       : 郭鹏超
 * Date         : 2024-11-13 16:30
 * LastEditors  : 苏军志
 * LastEditTime : 2025-02-03 15:43
 * Description  : 
 * CodeIterationRecord: 
 -->

<template>
  <div class="aline-left">
    <label v-if="label">{{ label }}</label>
    <el-select class="w-130!" :disabled="disabled" :clearable="clearable" v-model="genderValue" @change="changeValue">
      <el-option v-for="(gender, index) in genderList" :key="index" :label="gender.label" :value="gender.value"></el-option>
    </el-select>
  </div>
</template>

<script setup lang="ts">
const props = defineProps({
  modelValue: {
    type: Number
  },
  disabled: {
    type: Boolean,
    default: false
  },
  clearable: {
    type: Boolean,
    default: false
  },
  label: {
    type: String,
    default: undefined
  },
  // 是否添加全部
  isAddCommon: {
    type: Boolean,
    default: false
  }
});
const { isAddCommon } = props;
const genderList = computed(() => {
  //后续走配置
  const list = [
    { label: "男", value: 1 },
    { label: "女", value: 2 }
  ];
  if (!isAddCommon) {
    return list;
  }
  return [{ label: " ", value: 999999 }, ...list];
});
const emits = defineEmits(["update:modelValue", "change"]);
let genderValue = useVModel(props, "modelValue", emits);

const changeValue = (value: number) => {
  emits("change", genderList.value.find((item: any) => item.value == value) ?? {});
};
</script>
